package com.jp.knowledge.activity;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jiayen.dialog.LoadingDialog;
import com.jp.knowledge.R;
import com.jp.knowledge.comm.JpApplication;
import com.jp.knowledge.dialog.ToLoginDialog;

import org.xutils.common.util.DensityUtil;

/**
 * Created by jiayen on 16/9/26.
 */
public class BaseFragment extends Fragment {

    protected TextView topName;
    protected TextView  topDesc;
    protected ImageView leftIcon;
    protected ImageView rightIcon;
    protected ImageView mostRightIcon;

    protected JpApplication application;
    protected ToLoginDialog toLoginDialog;
    protected Context mContext;
    protected LoadingDialog loadingDialog;
    protected  TextView  rightBtn;

    protected boolean  isVisible =false;
    protected   int screenWidth;
    protected   int screenHeight;
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);

        if(getUserVisibleHint()) {
            isVisible = true;
            onVisible();
        } else {
            isVisible = false;
            onInvisible();
        }
    }
    /**
     * 可见
     */
    protected void onVisible() {
            onlazyLoad();
    }

    protected void onlazyLoad() {
    }

    /**
     * 不可见
     */
    protected void onInvisible() {

    }
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        application = (JpApplication) getActivity().getApplication();
        mContext = getActivity();
        toLoginDialog=new ToLoginDialog(mContext);
        loadingDialog = new LoadingDialog(mContext);
        screenWidth = DensityUtil.getScreenWidth();
        screenHeight = DensityUtil.getScreenHeight();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    }

    /**
     * 初始化导航栏
     */
    protected void initHead(View mView) {
        topName = (TextView) mView.findViewById(R.id.module_name);
        topDesc= (TextView) mView.findViewById(R.id.module_desc);
        leftIcon = (ImageView) mView.findViewById(R.id.icon_left);
        rightIcon= (ImageView) mView.findViewById(R.id.icon_serach);
        rightIcon.setVisibility(View.GONE);
        mostRightIcon= (ImageView) mView.findViewById(R.id.icon_right);
        rightBtn= (TextView) mView.findViewById(R.id.right_bn);
    }
}
